<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    request.setAttribute("path",path);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>用户管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="${path}/css/css.css" />
    <link rel="stylesheet" type="text/css" href="${path}/css/style.css" />
    <link rel="stylesheet" type="text/css" href="${path}/css/menu.css" />
    <link rel="stylesheet" type="text/css" href="${path}/css/address.css" />
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="${path}/layer/layer.js" type="text/javascript"></script>
    <script src="${path}/js/main.js" type="text/javascript"></script>
    <script src="https://cdn.bootcss.com/distpicker/2.0.3/distpicker.js"></script>
    <script type="text/javascript">
        function update(id, type,uid,nowPage) {
            var msg;
           let userStatus=type;
           let userId=uid;
           let nowPageS=nowPage
            if (type == 'N') {
                msg = "停用"
            } else {
                msg = "启用"
            }
            layer.confirm('确定要' + msg + '吗？', {
                btn : [ '确定', '取消' ]
                //按钮
            }, function() {
                $.post("UserServlet/Status",{"userStatus":userStatus,"userId":userId,"nowPageS":nowPageS},function (data) {
                    if (data==1){
                        alert(msg + '成功');
                        location.reload();
                    }else {
                        layer.msg('失败');
                    }
                    },"text");

            });
        }

        // function allTUser(pageNum) {
        //     $.post("UserServlet/allTUser", {
        //         "pageNum":pageNum,
        //         "beginTime":$("#beginTime").val(),
        //         "endTime":$("#endTime").val(),
        //         "userTel":$("#userTel").val()
        //     }, function(data) {
        //         console.log(data);
        //         var data = JSON.parse(data);
        //     });
        // }
    </script>
</head>
<%--onload="allTUser(1)"--%>
<body>
<div class="m-main">
    <div class="m-food">
        <div class="mf-top border-t">
            <div class="fl">用户管理</div>
            <div class="fr">
                <form action="UserServlet/allTUser" method="post">
                <input type="text" name="beginTime" value="${beginTime}" id="beginTime" placeholder="注册时间-始"
                       style="width: 100px;" />-<input type="text" name="endTime" value="${endTime}" id="endTime"
                                                       placeholder="注册时间-终" style="width: 100px;" /> <input type="text" value="${userTel}" name="userTel" id="userTel" placeholder="手机号码" />
               <button type="submit">查询</button>
                </form>
            </div>
        </div>
        <c:forEach items="${uList}" var="list">
        <div class="mf-menu border-t">
            <div class="fl">
                <span class="m-wt1"></span> <span>${list.userTel}</span> <span>${list.userName}</span>
                <span>男</span> <span>${list.addTime}</span>
            </div>
            <c:if test="${list.userRole eq 'A'}">
                <div class="fr">
                    <button class="xiajia" style="width: 200px">管理员</button>
                </div>
            </c:if>

            <c:if test="${list.userStatus eq 'Y'}">
                <c:if test="${list.userRole eq 'U'}">
                    <div class="fr">
                        <button class="xiajia" onclick="update(1,'N',${list.userId},${nowPage})">停用</button>
                    </div>
                </c:if>

            </c:if>
            <c:if test="${list.userStatus eq 'N'}">
                <c:if test="${list.userRole eq 'U'}">
                    <div class="fr">
                        <button class="xiugai" onclick="update(1,'Y',${list.userId},${nowPage})">启用</button>
                    </div>
                </c:if>

            </c:if>
        </div>
        </c:forEach>
        <div class="mf-top" style="margin-top: 30px">
            <ul class="pagination" style="margin-left: 250px">
                <c:forEach begin="1" end="${totalPage}" var="i" >
<%--   默认页--%>
                    <c:if test="${nowPage == i}">
                        <li><a class="active" href="UserServlet/allTUser?nowPage=${i}&beginTime=${beginTime}&endTime=${endTime}&userTel=${userTel}">${i}</a></li>
                    </c:if>
                    <c:if test="${nowPage != i}">
                        <li><a href="UserServlet/allTUser?nowPage=${i}&beginTime=${beginTime}&endTime=${endTime}&userTel=${userTel}">${i}</a></li>
                    </c:if>
                </c:forEach>
            </ul>
        </div>

    </div>
</div>
</body>
</html>
